home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / forth / 4th_hlp.com / 4TH.HLP < prev   
Encoding:
Text File  |  1988-10-13  |  18.9 KB  |  521 lines

  1.         INTRO.4TH
  2.        (ADVANTAGES OF FORTH)
  3.  
  4.     Preface:
  5.   The purpose of this file is not just to tell u "Forth is
  6. Great", but rather to clarify just what advantages Forth has
  7. over other languages, and to communicate th "feel" of Forth in
  8. relation to programming tasks.
  9.   I hope it does that job well enough to give u a sense of th
  10. possibilities, so that, when u pursue ur desire to see for
  11. urself what u can accomplish w/ it, u will be expecting to
  12. create elegance.  And if u are intent,  u will be gratified.
  13.   Please read this w/o bias, and if u doubt any statements
  14. made, th author is prepared to provide proof or acceptable
  15. evidence, or upload a corrected version of this file.
  16.   If, on th other hand, u are not willing to find out that
  17. there is a programming language considerably more capable &
  18. elegant than what u r familiar with, then better to not
  19. even give it a single quick scan! (grin)
  20.                                                     Giles
  21.  
  22.  
  23.     Topic Headings
  24.  
  25. Abreviation Definitions
  26. Commands That Fit
  27. Programming Environment
  28. Personal Experience
  29. What is Forth?
  30. Different Installations
  31. Examples
  32. Small Concept= Large Capability
  33. Grand Scale Programming
  34. Use
  35. My plans
  36. Your application
  37. Availability on CIS
  38. Learning Forth
  39. Social Aspects
  40. Problems
  41.  
  42.  
  43.     Abreviation Definitions
  44.  
  45. #, Number
  46. &, And
  47. cmd, Command
  48. hdw, Hardware
  49. r, Are
  50. sfw, software
  51. th, The
  52. u, You
  53. u're, You're
  54. ur, Your
  55. u've, You've
  56. w/, With
  57. w/o, Without
  58. 4th, Forth
  59.  
  60.  
  61.     Commands That Fit
  62.  
  63.   Have u ever wished:
  64.  
  65. 1. A particular command went about things just a little
  66. differently?
  67.  
  68. 2. A particular command behaved consistantly, rather than
  69. doing th wrong thing at just th wrong time?
  70.  
  71. 3. U had a particular command, that would make things
  72. SOOooooo simple?
  73.  
  74.   In Forth, th process of finding th code of a command &
  75. installing a rewritten version is trivial.
  76.  
  77.  
  78.     Programming Environment
  79.  
  80.   Have u ever felt that programming would always be a
  81. pleasant experience, if only U never had to program around
  82. bad system sfw?
  83.  
  84.   Have u ever wished:
  85.  
  86. 1. U could program twice as fast? ..Five times as fast?
  87. ..TEN times as fast?! And that u could debug th program as
  88. u write it, so that (generally) when u finished writing a
  89. module u wouldn't have to come back to it?
  90.  
  91. 2. That all th clever little subroutines u've worked out
  92. were instantly available, w/o having to look for them, or
  93. take any special pains to integrate them into th present
  94. program.
  95.  
  96. 3. That calling a subroutine required nothing more than
  97. naming it?
  98.  
  99. 4. That someway ur programming environment would help u
  100. keep track of where u r, & how th routine u r working on
  101. now will affect other routines, or which ones will be
  102. affected?
  103.  
  104. 5. That u could change th way ur compiler behaves?  Or that u
  105. could add th ability to handle special cases w/o changing
  106. anything else?
  107.  
  108. 6. That u could use hi-level commands, & a magic genie would
  109. come along & convert them to efficient machine code?  Or maybe
  110. just th ones needing speed, & leaving th others in th most
  111. compact form to save memory?
  112.  
  113. 7. That u never had to worry about linking library routines, or
  114. that ONE copy of routines would suffice for ALL processes?
  115.  
  116. 8. That u could have a multitasking, multiuser operating system
  117. w/ all th features of, say for instance, OS9, but ALSO have th
  118. immediate utility of a powerful toolbox & programming language
  119. combined?
  120.  
  121. 9. That u could bring th same, familiar environment &
  122. applications from obsolete hdw. to new hdw. w/ expanded
  123. capabilites, & easily add features to take advantage of th new
  124. hdw w/o having to change much if any of what u already have?
  125.  Examples: Transfer ur system & applications to a Tandy Color
  126. Computer in order to have graphix that beat some MS-DOS &
  127. Macintosh machines at a fraction of th price.
  128.  Or to an IBM styled machine, in order to take advantage of all
  129. th hdw options available, yet having an EFFECTIVE multasker,
  130. instead of being stuck w/ OS2.
  131.  
  132. 10. That u had a powerful environment on which u could write a
  133. similar environment, (but with all ur own improvements, of
  134. course), and compile th new environment & have a system of ur
  135. very own, w/ no royalties owed to anyone?  (Perhaps for ur own
  136. system to be manufactured & sold.)
  137.  
  138. 11. To have th ability to implement other languages, such
  139. as BASIC, LISP, Pascal, Prolog simply & efficiently?
  140.  
  141.   In Forth, u can move about freely. There is no "black
  142. box" compiler to shackle u w/ unnecessary restraints.  No
  143. restriction to predefined data structures.  U cannot get
  144. lost in GOTOs or jumps because 4th neither has nor needs
  145. them.
  146.   Forth assumes u know what u r doing, & often how u do it is
  147. implicit.
  148.  
  149.  
  150.     Personal Experience
  151.  
  152.   Before I knew of the existance of Forth I knew I would
  153. have to have a language that was infinitely extensible, and
  154. selfcompiling to do the things I wanted to do.  When I
  155. learned what Forth was, it was like manna from heaven.
  156.   With systems such as OS9 having some of th advantages of
  157. Forth, & excellent file handling, and w/ the availability
  158. of a powerful text editor such as TSEdit, a person has a
  159. very effective system for gathering textual data piecemeal
  160. & editing it.
  161.   But in using such a system, I have had to program around
  162. deficiencies of other languages,  been so hampered in
  163. reaching the hdw. functions of the machine, that some
  164. applications that should have been done were not practical
  165. to tackle, (because of time restraints) and as a result
  166. been forced to use sfw for which we haven't the source. 
  167. And so have been unable to adapt it exactly to our needs,
  168. or add enhancements and upgrades that we should have had.
  169.   So, I am FORCED to incorporate the advantages of OS9 into
  170. Forth, as I can no longer do without 4th's other, inherent
  171. advantages.
  172.  
  173.  
  174.     What is Forth?
  175.  
  176.   Forth is an infinitely extensible metacompilable
  177. language/op system in which subroutining is inherent.
  178. (Metacompilable is a Forth term meaning it can compile new
  179. versions of itself from source)
  180.   The stack's use is direct and largely automatic, and you
  181. can directly manipulate it.
  182.   Tho most implementations are sparse from an applications
  183. viewpoint, (tho I know of none that do not include an
  184. editor & assembler), it is so trivial to extend it, that
  185. you can relatively easily write a LISP or BASIC
  186. interpreter, C compiler, or a Prolog extension. (I have
  187. seen most of these in sigs or elsewhere.)
  188.   Since Forth is so compact, (it compiles to only
  189. subroutine addresses), and so fast, (tho slower than
  190. Machine Lang. to do exactly the same operations,
  191. practically it's often faster, because of the better
  192. organization of the functional blocks), and it can
  193. duplicate the power of any existing language, as well as
  194. any you dream up that are MORE powerful, it's hard to deny
  195. that Forth can be the MOST powerful language there is.  As
  196. a practical matter, complete control is in the programmer's
  197. hands, so the extensions will be just as bad as the
  198. programmer forces them to be! (grin)
  199.   On the other hand, you don't have to say "stupid compiler
  200. writer! Why didn't he do it THIS way?!".  You can just
  201. recompile the whole system to suit yourself!  Good idea to,
  202. because that way, it is your own system. to sell as an
  203. application, developmment system, arcade game, or whatever,
  204. with no royalties owed to anyone, and as a complete
  205. standalone system.
  206.  
  207.  
  208.     Different Installations
  209.  
  210.   It is also easily transportable.  You can redefine the
  211. primitives for the new cpu, and recompile it, with all the
  212. resources of the present system at hand.
  213.   And because of th small # of necessary primitives, & of
  214. th extreme modularity & interactive method of programming
  215. this allows, u will not believe how easy such a port is
  216. until u see it!
  217.  
  218.  
  219.     Examples
  220.  
  221.   You may know that the RSdos BASIC PALETTE cmd (for th
  222. Coco) takes a slot number (0-15) and puts a color value
  223. (0-63) into it.  The zero slot's hdw address is 65456.  So
  224. I defined a PALETTE cmd in Forth thusly:
  225.   : PAL -80 + C! ;
  226.   : is a word called Colon, and is the most commonly used
  227. compiler. It enters the following word, (a word is a group
  228. of non-space characters bounded by spaces, in this case
  229. PAL), into the dictionary, and compiles the addresses of
  230. the following words, (which normally must have already been
  231. defined), into the dictionary as it's definition.
  232.   -80 is the signed 16 bit integer equivalent of 65456.
  233. Mention of a number puts it on the stack.
  234.   + takes the 2 top stack entries and adds them, leaving
  235. the result on top of the stack.
  236.   ! is pronounced "store". It takes the second stack item
  237. and stores it in the address on top of the stack. But it
  238. stores SIXTEEN bit values. In this case we only want to
  239. store 1 byte, so we use Cstore, C being for "character". Of
  240. course C! is a different word from !.
  241.   ; terminates all definitions started with :.
  242.   So now instead of PALETTE8,38 as I would use in basic, I
  243. can do 38 8 PAL.
  244.   38 pushes 38 on the stack.
  245.   8 pushes on the 8.
  246.   PAL first takes the top item and adds it and 65456 to
  247. give the address of slot 8, then stores 38 (second stack
  248. item) into one byte at that address. And all of a sudden,
  249. your text is orange.(grin)
  250.   To make this cmd "system independent", you could first
  251. define a constant, SL0T, thusly:
  252.  65456 CONSTANT SL0T
  253.  (Constant is a compiling word that compiles...You got it,
  254. Constants! (grin)
  255.   Then define PAL thusly:
  256.  : PAL SL0T + C! ;
  257.   That way, only SL0T would have to be changed for another
  258. system. All system dependent values could be stored in a
  259. single place, and so be easy to set up for a different
  260. system.
  261.   Here's an edited example of th procedure for installing a
  262. rewritten primitive, as explained by my friend Bob McIsaac:
  263. --------------
  264.  ' <EMIT> DUMP ..display code being used.
  265.   You can figure a new version then install the hex code
  266. using:
  267.  CREATE EMIT NNNN , NNNN , NNNN , NEXT SMUDGE
  268.   If it works then install it:-
  269.  ' EMIT ' <EMIT> CFA ! FREEZE
  270.   This works because the code field addrs of a word always
  271. points to executable code and this can be anywhere in
  272. memory.
  273. ---------------
  274. In this example:
  275.   A dictionary header is made up like this:
  276. Up to th 1st 31 bytes are th name field.
  277. Next 2 bytes are th LINK FIELD, which points to th
  278. previously defined word.
  279. Next 2 bytes r th CODE FIELD, & point to executable code.
  280. (Th following parameter field, if th word is a primitive.)
  281. The remaining bytes r th PARAMETER FIELD, which may contain
  282. executable code, addresses for other words, variable
  283. storage, constant storage, tables, or what have u.
  284.   ' (pronounced "tick") puts th PFA (Parameter Field
  285. Address) of th word following it, on th stack.
  286.   DUMP gives a hex dump starting at th address on th stack.
  287.   CREATE creates a dictionary header for th word following
  288. it, in which th 1st character is altered (smudged, by
  289. flipping a bit) so that it can't be found, (while it is
  290. being defined).
  291.   , (Comma) Inserts th 16 bit value on top th stack at th
  292. current end of th dictionary, & bumps th dictionary pointer
  293. 16 bits, (to th NEW end of dictionary).
  294.   NEXT puts code in place for a "return" for th virtual
  295. Forth machine.
  296.   SMUDGE flips th flipped bit in th altered letter of th
  297. keyword, so that actually, in this case, it's working more
  298. like an "unsmudge". (grin)
  299.   CFA takes a PFA & converts it to a CFA (Code Field
  300. Address). In this case, th PFA of <EMIT> is converted to
  301. its CFA
  302.   ! Takes th second stack item (in this case, th PFA of
  303. EMIT) & stores it in 16 bits at th address on top of th
  304. stack, (in this case, th CFA of <EMIT>).
  305.   FREEZE sets th system so that it permanently recognizes
  306. this installation.
  307.  
  308.  
  309.     Small Concept= Large Capability
  310.  
  311.   Just a few additional concepts give u a great deal of
  312. added power.  Understanding "Compile time" & "Run time"
  313. behaviors of words, and "Compiling" words, allows u to do
  314. things in th most direct way possible.
  315.   And th "Reverse Polish Notation" use of th stack allows
  316. elimination of all other local variables.
  317.   I find Forth the easiest language in which to
  318. conceptualize a task.  Many procedures that would not be
  319. trivial in any OTHER design of language, can b programed in
  320. Forth out of hand.  Each part of the problem can always be
  321. programmed seperately, as a preliminary word to the final
  322. word that does the whole job.  Also you can start out with
  323. a word that just handles limited conditions, and keep
  324. adding new functions to it as you elaborate on the problem.
  325.  If you choose word names carefully, Forth is self
  326. documenting, also you can add comments inside (or outside,
  327. of course), the definition.
  328.  
  329.  
  330.     Grand Scale Programming
  331.  
  332.   I have talked about designing or redesigning whole
  333. systems, for customization, or porting to new hdw, & I
  334. expect it sounds like something that someone might spend
  335. months, or maybe even years doing, but it more likely would
  336. take u only a matter of days, because:
  337.  
  338. 1. Forth systems tend to be very small
  339.  
  340. 2. U usually have th tools to do things in th most direct
  341. way possible.  When u don't, u can MAKE them.
  342.  
  343. 3. Th combination of interactive programing w/ very small
  344. modules which are all subroutines usable individually,
  345. allows u to very efficiently "snowball" th power of ur
  346. code.  In other words, tho in any language a good
  347. programmer tries to write code whose power increases
  348. geometrically w/ th amount of code he writes, Forth was
  349. designed to allow u to do this very efficiently.
  350.  
  351. 4. Th modularity, interactivity, use of subroutines by
  352. naming them, as well as automatic stack use, makes
  353. debugging a breeze!
  354.  
  355.  
  356.     Use
  357.  
  358.   You can code interactively, at the term, to test things,
  359. but then for real work, you enter the editor, and edit
  360. scripts or source onto disk.
  361.   Then you can take input from disk with a LOAD cmd, and do
  362. execution and compiling directly from disk (until your file
  363. gives the cmd to take input from term).
  364.   Forth can accomplish everything OS9 can, simpler.
  365.  
  366.  
  367.     My plans
  368.  
  369.   I've always wanted to write my own OS because I
  370. eventually wanted to put out my own hdw, and wanted
  371. complete control of maintenance and no royalties. There are
  372. many PD Forths, and Forth workalikes out there to build
  373. upon.
  374.   The system I want to develop now, would include
  375. "Universal Random Block Access", or URBA which means the
  376. ability to access all common disk formats, (Mac, MSdos,
  377. Amiga, OS9, RSdos, CPM, ProDOS, CDOS, etc.)  Each format
  378. description would be contained in a "DOS Descriptor Block"
  379. data structure, and if a new format became popular, you
  380. could just add another DDB.  With additional device
  381. descriptors, and drivers, you could access WORMs, and VHS,
  382. etc.
  383.   Naturally it will have multitasking, & I want to add all
  384. the most useful commands of OS9.  Of course it will always
  385. have the advantage of being a programming lang. as well as
  386. an OS, over OS9.
  387.  
  388.  
  389.     Your Application
  390.  
  391.   Altho there are versions that run on top of OS9, Flex,
  392. CPM, MSdos, etc., etc, to get the greatest advantages, you
  393. need Forth on the bottom!
  394.  
  395.  
  396.     Availability on CIS
  397.  
  398.   Put your checkbook away!  You can get versions of Forth
  399. for the popular CPUs for down-load time:
  400.  
  401.     6809
  402.  
  403.   The TIL09 system is on Cocosig (g coco), in "Languages &
  404. Op. Systems" Lib.  It makes ROM calls on the Tandy Color
  405. Computer.
  406.   Here is a list of necessary files:
  407. TIL09.DOC, &
  408. M4TH.DOC, Describe operation & capabilities of TIL09.
  409. TEDIT.DOC, Describes editor use, & other necessary commands
  410. imbedded in th editor.
  411. TILBUG.4TH, Bug fixes.
  412. TIL09.GLO, System glossary.
  413. TILASM.DOC, Overview of assembler.
  414. TIL09.BIN, Executable system.  From BASIC, do
  415. LOADM"TIL09":EXEC. Uses logical sector/block disk access.
  416. TILDOS.ARC, TILDOS uses RSDOS disk files. Instructions are
  417. included.
  418. META1.BIN, &
  419. META2.BIN, are source for TIL09.
  420. TDCMP.BIN, is source for th metacompiler/decompiler.
  421. TEDIT.BIN, is th source for th editor.
  422. TILASM.4TH, source for th assembler.
  423.  
  424.     68000
  425.  
  426.   Do a g clm332 to get to Computer Languages Magazine's
  427. forum, & there, in th Forth library u can find:
  428.   README.68K, installation instructions.
  429.   F83-68.BIN, the executable Forth system. (Uses CPM disk
  430. access.)
  431.   KER68K.SCR, source, necessary for adapting the system &
  432. helpful in understanding it.
  433.   META68.SCR, source for the metacompiler, n case you want
  434. to alter the system, or make a completely new one.
  435.   UTL68K.SCR, source for utilities.
  436.   Atari16 forum has basically th same forth as F83-68K, but
  437. different disk access extensions for a non CP/M Forth.
  438.  
  439.     8086
  440.  
  441.   Also in CLM's Forth Libr.:
  442. README.PC, Dox for MS-DOS 4th.
  443. CMD4TH.BIN, IBM-PC dedicated Forth. (Does NOT go thru
  444. PC-DOS)
  445. F83-86.BIN, DOES go thru PC/MS-DOS.
  446. KER-86.SCR, System source.
  447. CPU-86.SCR, Assembler source.
  448. META86.SCR, Metacompiler source.
  449.  
  450.     8080
  451.  
  452.   Also in CLM's Forth Libr.:
  453. README.80, Dox.
  454. KERNAL.SCR, System source. (CPM80)
  455. F83-80.BIN, Executable system.(CPM80)
  456.  
  457.  
  458.     Learning Forth
  459.  
  460.   For a first text, I'd recommend:
  461.  "Starting Forth" by Leo Brodie.  A glossary is in Cocosigs
  462. DL9...
  463.  TIL09.GLO.  Maybe not Forth '83 de rigueur, but it is
  464. helpful.  Th entire text for th:
  465.  Forth '83 Standard is available in th Forth forum, (g
  466. forth), as FORTH-.DOC.
  467.   There is also a reference file in Forth lib in CLM (g
  468. clm332)....
  469.  4THRES.TX0 (Forth resorce).  You will also find FIG's
  470. address in here.
  471.   We r planning a 4th workshop in Cocosig.  Anyone
  472. interested may contact me for th schedule.
  473.   Also, if anyone knows of other live "Forth
  474. Introductions", I'll appreciate hearing of them.
  475.  
  476.  
  477.     Social Aspects
  478.  
  479.   There are people, some of whom r pretty good programmers,
  480. that consider Forth a "Cult" language.  I've tried to figure
  481. why this is so, (*I* don't feel like a cultist.(grin)), & so
  482. far I've come up w/ these possibilities:
  483.  
  484. 1. Forth IS after all fundamentally "different" from any
  485. other language. (Despite its similarity to LISP.)
  486.  
  487. 2. Once some people realize how much they can accomplish w/
  488. Forth, they may get overexcited, & sound as tho they have
  489. gone overboard! (Hehe..couldn't happen to ME!)
  490.  
  491. 3. I think it likely that Forth is better than what they
  492. (th people that call it a "cult" lang.) are used to, & maybe,
  493. for whatever reason, they would rather not find that out!(grin)
  494.  
  495. 4. Tho Forth tends to attract good programmers, (Th best!),
  496. it also attracts a few poor ones.  (I once saw a guy use a
  497. whole screen to define a single primitive. (grin))  Such a
  498. programmer is not likely to present Forth to a newcommer in
  499. its best light, also if th newcommer is himself a fairly
  500. good programmer, he's likely to figure that if his less
  501. capable friend thinks well of a language, it's probably a
  502. dud! hehe
  503.   So, then, if he hears th enthusiasm of someone who really
  504. knows & uses th potential of Forth somewhere near its
  505. fullest, he's likely to attribute such enthusiasm to
  506. "cultism". (grin).
  507.  
  508.  
  509.  
  510.     Problems
  511.  
  512.  Plex or contact me as follows:
  513.   Giles Spruill 73347,2651
  514.   Advanced Automation, Inc.
  515.   1217 N.E. Miami Ct., Suite 6
  516.   Miami, FL 33132
  517.   Ph# (305) 371-6408
  518.  
  519. I would also appreciate any advice that would help make
  520. this file better.